#pragma once

using namespace System;
using namespace System::IO;
using namespace NUnit::Framework;
using namespace LatoolNet;

namespace LatoolNetTest {

	[TestFixture]
	public ref class PolynomialTest {
	public:

		[Test]
		void TestCoefficientsForDimension3() {

			//This test case verifies that 
			//0.4 * (x - 0.1)^3 + 0.3 * (x - 0.1)^2 + 0.2 * (x - 0.1) + 0.1
			//is expanded to
			//0.4 * x^3  + 0.18 * x^2  + 0.152 * x + 0.0826

			int dimension = 3;
			array<double>^ origcoefs = gcnew array<double>(dimension + 1);
			origcoefs[0] = 0.1;
			origcoefs[1] = 0.2;
			origcoefs[2] = 0.3;
			origcoefs[3] = 0.4;
			double offset = 0.1;
			
			array<double>^ expectedcoefs = gcnew array<double>(dimension + 1);
			expectedcoefs[0] = 0.0826;
			expectedcoefs[1] = 0.152;
			expectedcoefs[2] = 0.18;
			expectedcoefs[3] = 0.4;
			Polynomial^ p = gcnew Polynomial(origcoefs, offset);
			array<double>^ actualcoefs = p->Coeffcients;
			for (int i = actualcoefs->Length - 1; i >= 0; i = i - 1) {
				Assert::AreEqual(expectedcoefs[i], actualcoefs[i], 1e-10, "Test: Polynomial");
			}
		};

		[Test]
		void TestCoefficientsForDimension4() {

			//This test case verifies that 
			//0.9 * (x - 0.3)^4 + 0.8 * (x - 0.3)^3 + 0.7 * (x - 0.3)^2 + 0.6 * (x - 0.3) +  0.5
			//is expanded to
			//0.9 * x^4  - 0.28 * x^3  + 0.466 * x^2  + 0.2988 * x + 0.36869

			int dimension = 4;
			array<double>^ origcoefs = gcnew array<double>(dimension + 1);
			origcoefs[0] = 0.5;
			origcoefs[1] = 0.6;
			origcoefs[2] = 0.7;
			origcoefs[3] = 0.8;
			origcoefs[4] = 0.9;
			double offset = 0.3;
			
			array<double>^ expectedcoefs = gcnew array<double>(dimension + 1);
			expectedcoefs[0] = 0.36869;
			expectedcoefs[1] = 0.2988;
			expectedcoefs[2] = 0.466;
			expectedcoefs[3] = -0.28;
			expectedcoefs[4] = 0.9; 
			Polynomial^ p = gcnew Polynomial(origcoefs, offset);
			array<double>^ actualcoefs = p->Coeffcients;
			for (int i = actualcoefs->Length - 1; i >= 0; i = i - 1) {
				Assert::AreEqual(expectedcoefs[i], actualcoefs[i], 1e-10, "Test: Polynomial");
			}
		};

	};
}
